﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Quicklight.Web.Events {
   
   public class EventDistributer<T> {
      private List<Action<T>> subscribers;

      public EventDistributer() {
         subscribers = new List<Action<T>>();
      }

      public void Publish(T t) {
         foreach (Action<T> subscriber in subscribers)
            subscriber(t);
      }

      public void Subscribe(Action<T> subscriber) {
         if (!subscribers.Contains(subscriber))
            subscribers.Add(subscriber);
      }

      public bool Contains(Action<T> subscriber) {
         return subscribers.Contains(subscriber);
      }

      public void Unsubscribe(Action<T> subscriber) {
         subscribers.Remove(subscriber);
      }
   }
}
